package cn.codeinn.service1.service.impl;

import java.util.concurrent.Future;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import cn.codeinn.service1.service.AsyncService;

@Service("asyncService")
public class AsyncServiceImpl implements AsyncService {

	@Override
	@Async
	public Future<String> testAsync1() {
		System.out.println("--start the test1 of async method");
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("--end the test1 of async method");
		return new AsyncResult<String>("async result");
	}

	@Override
	@Async
	public String testAsync2() {
		System.out.println("--start the test2 of async method");
		try {
			Thread.sleep(20000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("--end the test2 of async method");
		return "another result";
	}

}
